<template>
  <div v-if="show">
    <el-dialog :visible.sync="dialogVisible" fullscreen append-to-body>
      <el-container>
        <el-main style="height:calc(100vh  - 160px); padding: 0 45px;">
          <div class="score">
            <el-button type="primary" @click="exportExcel(cepingHzglb.hzName)">导出统计表</el-button>
            <el-button type="primary" @click="viewMxAll(0)">综合得分明细</el-button>
          </div>
          <div class="customTableHeader">
            <div class="customTableTitle">{{ cepingHzglb.hzName }}</div>
          </div>
          <div class="cpTable">
            <el-table ref='cpphztj-table' :data="cepingHzglDxpzbList" border stripe height="calc(100vh - 287px)">
              <el-table-column label="序号" width="100" type="index">
              </el-table-column>
              <el-table-column prop="deptName" label="部门" min-width="200" header-align="center" align="center">
                <template slot-scope="scope">
                  <span v-if="cepingHzglb.hzDx=='个人'">
                    {{ scope.row.deptName }}
                  </span>
                  <span v-else>
                    {{ scope.row.deptName }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="userName" label="姓名" min-width="200" header-align="center" align="center"
                               v-if="cepingHzglb.hzDx=='个人'">
                <template slot-scope="scope">
                  <span>
                    {{ scope.row.userName }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="userZw" label="职务" min-width="200" header-align="center" align="center"
                               v-if="cepingHzglb.hzDx=='个人'">
              </el-table-column>
              <!-- <el-table-column v-for="(item,index) in cList" :key="index" :prop="item"
                               :label="getcpName(item)" min-width="150" header-align="center" align="center">
              </el-table-column> -->
              <el-table-column label="总票数"  header-align="center" align="center">
                  <template slot-scope="scope">
                                   <span>{{getcphzps(scope.row.deptId,scope.row.userId)}}</span>
                                </template> 
              </el-table-column>
              <el-table-column v-for="(it,index) in dcgzList" :label="it.dcName" :key="index" header-align="center" align="center">
                                <template slot-scope="scope">
                                   <span>{{getcphzName(scope.row.deptId,scope.row.userId,it.dcName)}}</span>
                                </template>   
              </el-table-column>
              <!-- <el-table-column prop="df" label="等次得分11" min-width="150" header-align="center" align="center">
                <template slot-scope="scope">
                  <span>
                    {{ keepTwoDecimalFull(scope.row.df,2) }}
                  </span>
                </template>
              </el-table-column> -->
              <!-- <el-table-column prop="dcName" label="评价等次" min-width="150" header-align="center" align="center"
                               >
              </el-table-column>
              <el-table-column prop="cj" label="测评成绩" min-width="150" header-align="center" align="center"
                               >
                  <template slot-scope="scope">
                    <span>
                    {{ keepTwoDecimalFull(scope.row.cj,2) }}
                  </span>
                    </template>             
              </el-table-column> -->
              <!-- <el-table-column prop="jg" label="成绩评价等次" min-width="150" header-align="center" align="center"
                               v-if="pmShow">
              </el-table-column> -->
            </el-table>
          </div>
        </el-main>
      </el-container>
      <span slot="footer" class="dialog-footer flex justifyContentSpaceBetween" style="text-align:right;display: block">
        <!-- <div class="flex alignItemsCenter">
          <div class="font16">
            排名设置：<el-checkbox v-model="pmShow">显示排名</el-checkbox>
          </div>
          <div v-if="pmShow" style="margin:0 10px">
            <el-button type="primary" @click="szDialogVisible = true">排名设置</el-button>
          </div>
          <div v-if="cepingHzglb.hzFs == '公式' && cepingHzglb.hzGssm " style="margin:0 10px">
            综合得分 = {{ cepingHzglb.hzGssm }}
          </div>
        </div> -->
        <el-button @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
    <el-dialog title="排名设置" :visible.sync="szDialogVisible" width="150wh" append-to-body>
      <el-container>
        <el-main style="max-height:60vh">
            <el-col :span="24" style="margin-bottom:15px;">
              <el-col :span="8">
                <el-input v-model="pmName[0]" style="width: 80%;"></el-input>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[0]" :min="pm[3]+1" :max="pm[1]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align:center">
                <span>-</span>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[1]" :min="pm[0]+1"style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
            </el-col>
            <el-col :span="24" style="margin-bottom:15px;">
              <el-col :span="8">
                <el-input v-model="pmName[1]" style="width: 80%;"></el-input>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[2]" :min="pm[5]+1" :max="pm[3]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align:center">
                <span>-</span>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[3]" :min="pm[2]+1" :max="pm[0]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
            </el-col>
            <el-col :span="24" style="margin-bottom:15px;">
              <el-col :span="8">
                <el-input v-model="pmName[2]" style="width: 80%;"></el-input>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[4]" :min="pm[7]+1" :max="pm[5]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align:center">
                <span>-</span>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[5]" :min="pm[4]+1" :max="pm[2]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
            </el-col>
            <el-col :span="24" style="margin-bottom:15px;">
              <el-col :span="8">
                <el-input v-model="pmName[3]" style="width: 80%;"></el-input>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[6]" :min="pm[9]+1" :max="pm[7]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align:center">
                <span>-</span>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[7]" :min="pm[6]+1" :max="pm[4]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
            </el-col>
            <el-col :span="24" style="margin-bottom:15px;">
              <el-col :span="8">
                <el-input v-model="pmName[4]" style="width: 80%;"></el-input>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[8]" :min="0" :max="pm[9]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align:center">
                <span>-</span>
              </el-col>
              <el-col :span="7">
                <el-input-number v-model="pm[9]" :min="pm[8]+1" :max="pm[6]-1" style="width: 90%;"  class="ml10"></el-input-number>
              </el-col>
            </el-col>
            <!-- <div v-show="pm[0] > 100" class="red">* 输入的范围小于100%</div>
          <div style="margin-bottom:20px;margin-left: 30px;">
            <el-input v-model="pmName[1]" style="width: 100px;" :disabled="true"></el-input>
            <el-input-number v-model="pm[1]" :min="0" class="ml10"></el-input-number>
            %
            <div v-show="pm[1] > 100" class="red">* 输入的范围小于100%</div>
          </div>
          <div style="margin-bottom:20px;margin-left: 30px;">
            <el-input v-model="pmName[2]" style="width: 100px;" :disabled="true"></el-input>
            <el-input-number v-model="pm[2]" :min="0" class="ml10"></el-input-number>
            %
            <div v-show="pm[2] > 100" class="red">* 输入的范围小于100%</div>
          </div>
          <div style="margin-bottom:20px;margin-left: 30px;">
            <el-input v-model="pmName[3]" style="width: 100px;" :disabled="true"></el-input>
            <el-input-number v-model="pm[3]" :min="0" class="ml10"></el-input-number>
            %
            <div v-show="pm[3] > 100" class="red">* 输入的范围小于100%</div>
          </div>
          <div style="margin-bottom:20px;margin-left: 30px;">
            <el-input v-model="pmName[4]" style="width: 100px;" :disabled="true"></el-input>
            <el-input-number v-model="pm[4]" :min="0" class="ml10"></el-input-number>
            %
            <div v-show="pm[4] > 100" class="red">* 输入的范围小于100%</div>
          </div> -->
        </el-main>
      </el-container>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="pmQr">确定设置</el-button>
        <el-button @click="szDialogVisible = false">关闭</el-button>
        
      </span>
    </el-dialog>
    <el-dialog title="明细查询" :visible.sync="mxDialogVisible" :width="getDjmx()?'1800px':'1200px'" append-to-body>
      <div style="margin-bottom:20px">
        <el-table ref="zbABTable" :data="mxList" border stripe height="400px">
          <el-table-column label="序号" width="100" type="index" header-align="center" align="center">
          </el-table-column>
          <el-table-column prop="cpCode" label="票种" min-width="60" header-align="center" align="center">
            <template slot-scope="scope">
              {{ scope.row.cpCode }}票
            </template>
          </el-table-column>
          <el-table-column prop="cpCsl" label="总票数" min-width="80" header-align="center" align="center">
            <template slot-scope="scope">
              {{ scope.row.cpCsl }}票
            </template>
          </el-table-column>
          <el-table-column prop="cpDsl" label="提交票数" min-width="100" header-align="center" align="center">
            <template slot-scope="scope">
              {{ scope.row.cpDsl }}票
            </template>
          </el-table-column>
          <el-table-column prop="cpQz" label="票种权重" min-width="100" header-align="center" align="center">
            <template slot-scope="scope">
              {{ scope.row.cpQz }}%
            </template>
          </el-table-column>
          <el-table-column prop="cpQzpjf" label="平均分数" min-width="120" header-align="center" align="center">
          </el-table-column>
          <el-table-column prop="cpqz" label="测评项权重" min-width="120" header-align="center" align="center"
                           v-if="getDjmx()">
            <template slot-scope="scope">
              {{ scope.row.cpqz }}%
            </template>
          </el-table-column>
          <el-table-column prop="cpQzpjfCph" label="测评项分数" min-width="120" header-align="center" align="center"
                           v-if="getDjmx()">
          </el-table-column>
          <el-table-column prop="dcqz" label="等次项权重" min-width="120" header-align="center" align="center"
                           v-if="getDjmx()">
            <template slot-scope="scope">
              {{ scope.row.dcqz }}%
            </template>
          </el-table-column>
          <el-table-column prop="cpQzpjfDch" label="等次项分数" min-width="120" header-align="center" align="center"
                           v-if="getDjmx()">
          </el-table-column>
          <el-table-column prop="cpQzpjfZzfs" label="测评分数" min-width="100" header-align="center" align="center"
                           v-if="getDjmx()">
          </el-table-column>
          <el-table-column prop="cppQz" label="测评票权重" min-width="120" header-align="center" align="center"
                           v-if="getCppQz()">
            <template slot-scope="scope">
              {{ scope.row.cppQz }}%
            </template>
          </el-table-column>
          <el-table-column prop="cppFz" label="最终分数" min-width="100" header-align="center" align="center"
                           v-if="getCppQz()">
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="exportExcelAB">导出</el-button>
        <el-button @click="mxDialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog :visible.sync="xqDialogVisible" v-if="xqDialogVisible" fullscreen append-to-body>
      <div v-if="mxLx=='pj'">
        <div class="score">
          <el-button type="primary" @click="exportExcelXq">导出</el-button>
        </div>
        <div class="customTableHeader">
          <div class="customTableTitle">{{ cepingHzglb.hzName }}</div>
        </div>
        <div style="margin-bottom:20px">
          <el-table ref='xqABTable' :data="cepingHzglDxpzbList" border stripe height="calc(100vh - 287px)">
              <el-table-column label="序号" width="100" type="index">
              </el-table-column>
              <el-table-column prop="deptName" label="部门" min-width="200" header-align="center" align="center">
                <template slot-scope="scope">
                  <span v-if="cepingHzglb.hzDx=='个人'">
                    {{ scope.row.deptName }}
                  </span>
                  <span v-else>
                    {{ scope.row.deptName }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="userName" label="姓名" min-width="200" header-align="center" align="center"
                               v-if="cepingHzglb.hzDx=='个人'">
                <template slot-scope="scope">
                  <span>
                    {{ scope.row.userName }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="userZw" label="职务" min-width="200" header-align="center" align="center"
                               v-if="cepingHzglb.hzDx=='个人'">
              </el-table-column>
              <el-table-column v-for="(item,index) in cList" :key="index" :prop="item"
                               :label="getcpName(item)" min-width="150" header-align="center" align="center">
                       
                               <!-- <el-table-column label="等次分值" :prop="item" min-width="100" header-align="center" align="center">
                            
                              </el-table-column> -->
                              <!-- <el-table-column label="测评等级"  min-width="100" header-align="center" align="center">
                                  <template slot-scope="scope">
                                    <span>{{getcejie(scope.row.deptId,scope.row.userId,item)}}</span>
                                  </template>
                              </el-table-column> -->
                              <el-table-column label="总票数"  min-width="100" header-align="center" align="center">
                                  <template slot-scope="scope">
                                      <span>{{getcpzps(scope.row.deptId,scope.row.userId,item)}}</span>
                                  </template>
                              </el-table-column>
                              <el-table-column v-for="(it,index) in dcgzList" :label="it.dcName" :key="index" header-align="center" align="center">
                                <template slot-scope="scope">
                                   <span>{{getcpdjName(scope.row.deptId,scope.row.userId,item,it.dcName)}}</span>
                                </template>   
                              </el-table-column>
              </el-table-column>
              <!-- <el-table-column prop="df" label="等次得分" min-width="150" header-align="center" align="center">
                <template slot-scope="scope">
                  <span>
                    {{ keepTwoDecimalFull(scope.row.df,2) }}
                  </span>
                </template>
              </el-table-column> -->
              <!-- <el-table-column prop="dcName" label="评价等次" min-width="150" header-align="center" align="center"
                               >
              </el-table-column>
              <el-table-column prop="cj" label="测评成绩" min-width="150" header-align="center" align="center"
                               >
                  <template slot-scope="scope">
                    <span>
                    {{ keepTwoDecimalFull(scope.row.cj,2) }}
                  </span>
                    </template>             
              </el-table-column> -->
              <!-- <el-table-column prop="jg" label="成绩评价等次" min-width="150" header-align="center" align="center"
                               v-if="pmShow">
              </el-table-column> -->
            </el-table>
          
        </div>
      </div>
      <div v-if="mxLx=='dfmx'">
        <div class="score">
          <el-button type="primary" @click="exportExcelXq">导出</el-button>
        </div>
        <div class="customTableHeader">
          <div class="customTableTitle">{{ cepingHzglb.hzName }}</div>
        </div>
        <div style="margin-bottom:20px">
          <el-table ref="xqABTable" :data="tableData" border stripe height="calc(100vh - 247px)">
            <el-table-column label="序号" width="100" type="index" header-align="center" align="center">
            </el-table-column>
            <el-table-column prop="hdName" label="被测评" min-width="150" header-align="center" align="center"
                             :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column :prop="'hj_'+t1.id" :label="t1.zbMc + (t1.zbQz>0?('('+t1.zbQz+'%)'):'')" min-width="175"
                             header-align="center" align="center"
                             v-for="(t1,i1) in cepingXmmxbListTree" :key="i1*10000">
              <el-table-column :prop="'hj_'+t2.id" :label="t2.zbMc + (t2.zbQz>0?('('+t2.zbQz+'%)'):'')" min-width="175"
                               header-align="center"
                               align="center" v-if="t1.children" v-for="(t2,i2) in t1.children"
                               :key="i1*10000+i2*100">
                <el-table-column :prop="'hj_'+t3.id" :label="t3.zbMc + (t3.zbQz>0?('('+t3.zbQz+'%)'):'')"
                                 min-width="175"
                                 header-align="center"
                                 align="center" v-if="t2.children" v-for="(t3,i3) in t2.children"
                                 :key="i1*10000+i2*100+i3">
                </el-table-column>
                <el-table-column label="得分" min-width="100" header-align="center" align="center">
                  <template slot-scope="scope">
                    {{ scope.row['hj_' + t2.id] }}
                  </template>
                </el-table-column>
                <el-table-column :label="x1+'票'" min-width="100" header-align="center" align="center"
                                 v-for="(x1,j1) in cList" :key="j1">
                  <el-table-column :label="'低于'+(xyfz/10)+'分票'" min-width="110" header-align="center" align="center">
                    <template slot-scope="scope">
                    <span v-if="scope.row[x1 + '_' + t2.id + '_xp']">
                    {{ scope.row[x1 + "_" + t2.id + "_df"] }}
                    </span>
                      <span v-else>
                      0
                    </span>
                    </template>
                  </el-table-column>
                  <el-table-column label="占比" min-width="80" header-align="center" align="center">
                    <template slot-scope="scope">
                    <span v-if="scope.row[x1 + '_' + t2.id + '_xp']">{{
                        scope.row[x1 + "_" + t2.id + "_df"] == 0 ? 0 : Math.round(scope.row[x1 + "_" + t2.id + "_df"] / scope.row[x1 + "_" + t2.id + "_xp"] * 10000) / 100
                      }} %
                    </span>
                      <span v-else>
                      0 %
                    </span>
                    </template>
                  </el-table-column>
                </el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column prop="cpFz" label="指标汇总" min-width="150" header-align="center" align="center">
              <template slot-scope="scope">
                {{ keepTwoDecimalFull(scope.row.cpFz, 2) }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div v-if="mxLx=='dfhz'">
        <div class="score">
          <el-button type="primary" @click="exportExcelXq">导出</el-button>
        </div>
        <div class="customTableHeader">
          <div class="customTableTitle">{{ cepingHzglb.hzName }}</div>
        </div>
        <div style="margin-bottom:20px">
          <el-table ref="xqABTable" :data="cepingHzglDxpzbList" border stripe height="calc(100vh - 247px)">
            <el-table-column label="序号" width="100" type="index">
            </el-table-column>
            <el-table-column prop="deptName" label="部门" min-width="200" header-align="center" align="center">
              <template slot-scope="scope">
                  <span v-if="cepingHzglb.hzDx=='个人'">
                    {{ scope.row.deptName }}
                  </span>
                <span v-else>
                    {{ scope.row.deptName }}
                  </span>
              </template>
            </el-table-column>
            <el-table-column prop="userName" label="姓名" min-width="200" header-align="center" align="center"
                             v-if="cepingHzglb.hzDx=='个人'">
              <template slot-scope="scope">
                  <span>
                    {{ scope.row.userName }}
                  </span>
              </template>
            </el-table-column>
            <el-table-column prop="userZw" label="职务" min-width="200" header-align="center" align="center"
                             v-if="cepingHzglb.hzDx=='个人'">
            </el-table-column>
            <el-table-column v-for="(item,index) in cList" :key="index" :prop="item"
                             :label="getcpName(item)" min-width="150" header-align="center" align="center">
            </el-table-column>
            <el-table-column prop="df" label="综合得分" min-width="150" header-align="center" align="center">
              <template slot-scope="scope">
              <span>
                {{ keepTwoDecimalFull(scope.row.df, 2) }}
<!--                {{ scope.row.df }}-->
              </span>
              </template>
            </el-table-column>
            <el-table-column :label="'低于'+(xyfz/10)+'分票情况说明'" min-width="250" header-align="center" align="left">
              <template slot-scope="scope">
                <span v-html="getDfsm(scope.row)"></span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer flex justifyContentSpaceBetween" style="text-align:right;display: block">
        <!-- <div class="flex alignItemsCenter">
          <div style="margin:0 10px">
            <el-button :type="mxLx == 'pj'?'primary':''" @click="setMxLx('pj')">测评平均成绩</el-button>
            <el-button :type="mxLx == 'dfmx'?'primary':''" @click="setMxLx('dfmx')">测评低于{{ xyfz / 10 }}分明细</el-button>
            <el-button :type="mxLx == 'dfhz'?'primary':''" @click="setMxLx('dfhz')">测评低于{{ xyfz / 10 }}分汇总</el-button>
          </div>
          <div class="font16" v-if="mxLx == 'dfmx'||mxLx == 'dfhz'">
            低分设置：<el-select v-model="xyfz" placeholder="请选择" @change="selectDf">
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
          </div>
        </div> -->
        <el-button type="primary" plain @click="xqDialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {hzInfo, hzInfo2, putObj} from '@/api/ceping/cepinghzglb'
import {hzInfo as hdhz, hzInfos} from '@/api/ceping/cepinghdglhdzhhzb'
import {bcpTjInfo} from '@/api/ceping/cepinghdglhdcphzb'
import {getBcpDfList, getBcpDfLists} from '@/api/ceping/cepinghdglxpxxdfjlbfb'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'

export default {
  name: "cepinghztj3Dialog",
  data() {
    return {
      show: false,
      dialogVisible: false,
      szDialogVisible: false,
      mxDialogVisible: false,
      xqDialogVisible: false,
      cepingHzglb: {},
      cepingHzglDxpzbList: [],
      cepingHzglHdfwbList: [],
      jlts: 0,
      pm: [100, 200,80,99,60,79, 50,59,0,49],
      pmName:["优秀", "良好", "中等", "及格", "差"],
      pmShow: true,
      mxList: [],
      cepingHdglCppmxbInfo: {},
      codeNameJson:{},
      cepingXmmxbListTree: [],
      xmxxXmmx: [],
      tableData: [],//指标结构
      cList: [],
      mxLx: "pj",
      xyfz: 50,
      options: [{
        label: '小于10分',
        value: 100
      }, {
        label: '小于9分',
        value: 90
      }, {
        label: '小于8分',
        value: 80
      }, {
        label: '小于7分',
        value: 70
      }, {
        label: '小于6分',
        value: 60
      }, {
        label: '小于5分',
        value: 50
      }, {
        label: '小于4分',
        value: 40
      }, {
        label: '小于3分',
        value: 30
      }, {
        label: '小于2分',
        value: 20
      }, {
        label: '小于1分',
        value: 10
      }],
      loading: null,
      hdInfos: {},
      dfInfos: {},
      dcgzList:[],
      dcgzVList:[],
      cList4DC:[],
      dcgzJGList:[],
      dchzVList:[]
    }
  },
  methods: {
    getcpName(cpCode){
      let tmp = this.codeNameJson[cpCode]
      let name = tmp ? tmp : cpCode
      return name
    },
    getcpdjName(bcpDeptId,bcpUserId,item,it){
      // dcgzVList
      let cpmxIds=this.cList4DCMap[item]
      cpmxIds.split(',')
      var name,dcZs=0
      if(bcpDeptId){
        for(var i in this.dcgzVList){
          //新调整代码 cpOcde 对应 多个cpCodeId
          // if(bcpDeptId==this.dcgzVList[i].bcpDeptId&&cpmxId===this.dcgzVList[i].cpmxId&&it==this.dcgzVList[i].dcName){
          if(bcpDeptId==this.dcgzVList[i].bcpDeptId&&(cpmxIds.indexOf(this.dcgzVList[i].cpmxId)!=-1)&&it==this.dcgzVList[i].dcName){
            dcZs=this.dcgzVList[i].dcZs*1
          }
        }
      }
      if(bcpUserId){
        for(var i in this.dcgzVList){
          //新调整代码
          if(bcpUserId==this.dcgzVList[i].bcpUserId&&(cpmxIds.indexOf(this.dcgzVList[i].cpmxId)!=-1)&&it==this.dcgzVList[i].dcName){
            dcZs+=this.dcgzVList[i].dcZs*1
          }
        }
      }
      return dcZs
    },
    getcpzps(bcpDeptId,bcpUserId,item){
      var dcZs,dcZss=0;
      for(var n in this.dcgzList){
         dcZs=this.getcpdjName(bcpDeptId,bcpUserId,item,this.dcgzList[n].dcName)
          if(dcZs){
            dcZss+=dcZs*1
          }
          
      }
      return dcZss
    },
    getcphzName(bcpDeptId,bcpUserId,dcName){
     
      var dcZs=0;
      for(var i in this.dchzVList){
        if(bcpUserId){
            if(bcpUserId==this.dchzVList[i].bcpUserId&&dcName==this.dchzVList[i].dcName){
              dcZs=this.dchzVList[i].dcZs
            }
        }
        if(bcpDeptId){
          if(bcpDeptId==this.dchzVList[i].bcpDeptId&&dcName==this.dchzVList[i].dcName){
            dcZs=this.dchzVList[i].dcZs
          }
        }
        
      }
      return dcZs
    },
    getcphzps(bcpDeptId,bcpUserId){
      var dcZs,dcZss=0;
      for(var i in this.dcgzList){
          dcZs=this.getcphzName(bcpDeptId,bcpUserId,this.dcgzList[i].dcName)
          if(dcZs){
            dcZss+=dcZs*1
          }
      }
      return dcZss
    },
    getcejie(bcpDeptId,bcpUserId,item){
      let cpmxId=this.cList4DCMap[item]
      
      //dcgzJGList
      var name,dcName;
      if(bcpDeptId){
        for(var i in this.dcgzJGList){
          if(bcpDeptId==this.dcgzJGList[i].bcpDeptId&&cpmxId==this.dcgzJGList[i].cpmxId){
            dcName=this.dcgzJGList[i].dcName
          }
        }
      }
      if(bcpUserId){
        for(var i in this.dcgzJGList){
          if(bcpUserId==this.dcgzJGList[i].bcpUserId&&cpmxId==this.dcgzJGList[i].cpmxId){
            dcName=this.dcgzJGList[i].dcName
          }
        }
      }
      return dcName
    },
    setMxLx(t) {
      this.mxLx = "";
      this.$nextTick(() => {
        this.mxLx = t;
      })
    },
    init(id) {
      const loading = this.$loading({
        lock: true,
        text: '正在汇总计算，请销后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      this.show = false;
      this.pm = [100, 200,80,99,60,79, 50,59,0,49];
      this.pmName =["优秀", "良好", "中等", "及格", "差"];
      this.pmShow = true;
      hzInfo2(id).then(res => {
        //console.log(res.data.data)
        if(res.data.data===-1){
          this.$notify.warning(res.data.msg);
          loading.close();
          return false;
        }
        this.cepingHzglb = res.data.data.cepingHzglb;
        if (this.cepingHzglb.hzJgbl) {
          this.pm = JSON.parse(this.cepingHzglb.hzJgbl).pm;
          this.pmName = JSON.parse(this.cepingHzglb.hzJgbl).pmName;
        } else {
          this.pm = [100, 200,80,99,60,79, 50,59,0,49];
          this.pmName = ["优秀", "良好", "中等", "及格", "差"];
        }
        this.cepingHzglHdfwbList = res.data.data.cepingHzglHdfwbList;
        function compareZb(a, b) {
          return b.df - a.df;
        }
        this.cepingHzglDxpzbList = res.data.data.hzRestlt.sort(compareZb);
        this.jlts = this.cepingHzglDxpzbList.length;
        //console.log("初始:"+JSON.stringify(this.cepingHzglDxpzbList))
        this.cList = res.data.data.cList.sort();
        this.codeNameJson = res.data.data.codeNameMap
        this.dcgzList=res.data.data.dcgzList;
        this.dchzVList=res.data.data.dchzVList;
        this.dcgzVList=res.data.data.dcgzVList;
        this.cList4DCMap=res.data.data.cList4DCMap;
        this.dcgzJGList=res.data.data.dcgzJGList;
        loading.close();
        this.show = true;
        this.dialogVisible = true;

        // let cList = [];
        // let x = 0;
        // for (let i in this.cepingHzglDxpzbList) {
        //   let row = this.cepingHzglDxpzbList[i];
        //   let mxList = [];
        //   bcpTjInfo(this.cepingHzglb.id, this.cepingHzglb.hzDx == "部门" ? row.deptId : (row.userLx == "班子" ? row.deptId : row.userId), this.cepingHzglb.hzDx == "部门" ? 2 : (row.userLx == "班子" ? 2 : 1)).then(res => {
        //     mxList = this.shujuHandle(res.data.data);
        //     for (var y in mxList) {
        //       if (cList.indexOf(mxList[y].cpCode) == -1) {
        //         cList.push(mxList[y].cpCode)
        //       }
        //       row[mxList[y].cpCode] = mxList[y].cppFz;
        //     }
        //     x++;
        //     if (x == this.jlts) {
        //       console.log(this.cepingHzglDxpzbList)
        //       this.cList = cList;
        //       loading.close();
        //       this.show = true;
        //       this.dialogVisible = true;
        //     }
        //   });
        // }
      })
    },
    pmQr() {
      let num = 0;
      for (var i in this.pm) {
        if (this.pm[i] == null) {
          this.pm[i] = 0;
          this.$set(this.pm, i, 0)
        }
        num += this.pm[i]
      }
      // if (num.toFixed(2) != 100) {
      //   this.$notify.closeAll();
      //   this.$notify.error("您设置的排名比率总和为“" + num + "%”，不是100%，无法这样应用");
      //   return;
      // }
      if (this.pm[1] > 0 && this.pm[0] == 0) {
        this.$notify.closeAll();
        this.$notify.error("您设置的排名" + this.pmName[1] + "为“" + this.pm[1] + "%”，但A为“0%”，无法这样应用");
        return;
      }
      if (this.pm[2] > 0 && this.pm[1] == 0) {
        this.$notify.closeAll();
        this.$notify.error("您设置的排名" + this.pmName[2] + "为“" + this.pm[2] + "%”，但B为“0%”，无法这样应用");
        return;
      }
      if (this.pm[3] > 0 && this.pm[2] == 0) {
        this.$notify.closeAll();
        this.$notify.error("您设置的排名" + this.pmName[3] + "为“" + this.pm[3] + "%”，但C为“0%”，无法这样应用");
        return;
      }
      if (this.pm[4] > 0 && this.pm[3] == 0) {
        this.$notify.closeAll();
        this.$notify.error("您设置的排名" + this.pmName[4] + "为“" + this.pm[4] + "%”，但D为“0%”，无法这样应用");
        return;
      }
      let data = {
        pm: this.pm,
        pmName: this.pmName
      }
      let info = {
        id: this.cepingHzglb.id,
        hzJgbl: JSON.stringify(data)
      }
      putObj(info).then(res => {
        this.szDialogVisible = false;
        this.init(this.cepingHzglb.id)
      })
    },
    /**
     * excel 导出
     */
    exportExcel(excelName) {
      try {
        const $e = this.$refs['cpphztj-table'].$el
        let $table = $e.querySelector('.el-table__fixed')
        if (!$table) {
          $table = $e
        }
        const wb = XLSX.utils.table_to_book($table, {
          raw: true
        })

        const wbout = XLSX.write(wb, {
          bookType: 'xlsx',
          bookSST: true,
          type: 'array'
        })
        FileSaver.saveAs(
          new Blob([wbout], {
            type: 'application/octet-stream'
          }),
          `${excelName}.xlsx`,
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.error(e)
      }
    },
    showMx(row) {
      this.mxList = [];
      bcpTjInfo(this.cepingHzglb.id, this.cepingHzglb.hzDx == "部门" ? row.deptId : (row.bcpDx == "班子" ? row.deptId : row.userId), this.cepingHzglb.hzDx == "部门" ? 2 : (row.bcpDx == "班子" ? 2 : 1)).then(res => {
        this.mxList = this.shujuHandle(res.data.data);
        this.mxDialogVisible = true;
      });
    },
    shujuHandle(list) {
      //console.log(list)
      var data = [];
      var datajg = [];

      for (var a in list) {
        if (data.length > 0) {
          var bz = true;
          for (var b in data) {
            if (data[b].cpCode == list[a].cpCode) {
              data[b].cpCsl = data[b].cpCsl + list[a].cpCsl;
              data[b].cpDsl = data[b].cpDsl + list[a].cpDsl;
              data[b].cpPjf = data[b].cpPjf + list[a].cpPjf;
              data[b].cpQz = data[b].cpQz + list[a].cpQz;
              data[b].cpQzpjf = data[b].cpQzpjf + list[a].cpQzpjf;
              data[b].cpQzpjfCph = data[b].cpQzpjfCph + parseFloat(list[a].cpQzpjfCph);
              data[b].cpQzpjfDch = data[b].cpQzpjfDch + parseFloat(list[a].cpQzpjfDch);
              data[b].cpQzpjfZzfs = data[b].cpQzpjfZzfs + parseFloat(list[a].cpQzpjfZzfs);
              data[b].cpWsl = data[b].cpWsl + list[a].cpWsl;
              data[b].cppFz = data[b].cppFz + parseFloat(list[a].cppFz);
              data[b].cppQz = data[b].cppQz + list[a].cppQz;
              data[b].cpqz = data[b].cpqz + list[a].cpqz;
              data[b].dcqz = data[b].dcqz + list[a].dcqz;
              data[b].cs = data[b].cs + 1;

              bz = false;
            }
          }

          if (bz) {
            data.push({
              cpCode: list[a].cpCode,
              cpCsl: list[a].cpCsl,
              cpDsl: list[a].cpDsl,
              cpPjf: list[a].cpPjf,
              cpQz: list[a].cpQz,
              cpQzpjf: list[a].cpQzpjf,
              cpQzpjfCph: parseFloat(list[a].cpQzpjfCph),
              cpQzpjfDch: parseFloat(list[a].cpQzpjfDch),
              cpQzpjfZzfs: parseFloat(list[a].cpQzpjfZzfs),
              cpWsl: list[a].cpWsl,
              cppFz: parseFloat(list[a].cppFz),
              cppQz: list[a].cppQz,
              cpqz: list[a].cpqz,
              dcqz: list[a].dcqz,
              cs: 1,
            });
          }
        } else {
          data.push({
            cpCode: list[a].cpCode,
            cpCsl: list[a].cpCsl,
            cpDsl: list[a].cpDsl,
            cpPjf: list[a].cpPjf,
            cpQz: list[a].cpQz,
            cpQzpjf: list[a].cpQzpjf,
            cpQzpjfCph: parseFloat(list[a].cpQzpjfCph),
            cpQzpjfDch: parseFloat(list[a].cpQzpjfDch),
            cpQzpjfZzfs: parseFloat(list[a].cpQzpjfZzfs),
            cpWsl: list[a].cpWsl,
            cppFz: parseFloat(list[a].cppFz),
            cppQz: list[a].cppQz,
            cpqz: list[a].cpqz,
            dcqz: list[a].dcqz,
            cs: 1,
          });
        }
      }

      for (var c in data) {
        datajg.push({
          cpCode: data[c].cpCode,
          cpCsl: data[c].cpCsl,
          cpDsl: data[c].cpDsl,
          cpPjf: parseFloat((data[c].cpPjf / data[c].cs).toFixed(2)),
          cpQz: parseFloat((data[c].cpQz / data[c].cs).toFixed(2)),
          cpQzpjf: parseFloat((data[c].cpQzpjf / data[c].cs).toFixed(2)),
          cpQzpjfCph: parseFloat((data[c].cpQzpjfCph / data[c].cs).toFixed(2)),
          cpQzpjfDch: parseFloat((data[c].cpQzpjfDch / data[c].cs).toFixed(2)),
          cpQzpjfZzfs: parseFloat((data[c].cpQzpjfZzfs / data[c].cs).toFixed(2)),
          cpWsl: data[c].cpWsl,
          cppFz: parseFloat((data[c].cppFz / data[c].cs).toFixed(2)),
          cppQz: parseFloat((data[c].cppQz / data[c].cs).toFixed(2)),
          cpqz: parseFloat((data[c].cpqz / data[c].cs).toFixed(2)),
          dcqz: parseFloat((data[c].dcqz / data[c].cs).toFixed(2))
        });
      }

      //console.log(datajg)
      return datajg;
    },
    viewMxAll(a) {
      this.loading = this.$loading({
        lock: true,
        text: '正在汇总计算明细，请销后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      let hdidsAll = [];
      for (var i in this.cepingHzglHdfwbList) {
        if (hdidsAll.indexOf(this.cepingHzglHdfwbList[i].hdId) == -1) {
          hdidsAll.push(this.cepingHzglHdfwbList[i].hdId)
        }
      }
    //  console.log("第一步:"+JSON.stringify(this.cepingHzglHdfwbList))
      hzInfos(hdidsAll.join()).then(res => {
        this.hdInfos = res.data.data;
        let response = this.getHdhz(hdidsAll.join());
       
       // console.log("this.dcgzList:"+JSON.stringify(this.dcgzList))
        this.viewMxAlls(0);

      })
    },
    getHdhz(id) {
      let res = {
        data: {
          data: this.hdInfos[id]
        }
      }
      return res;
    },
    viewMxAlls(a) {
      if (a == 0) {
        this.tableData = [];
      }
      this.loading.text = '正在汇总计算明细（' + (a + 1) + '/' + (this.cepingHzglDxpzbList.length) + '），请销后...';
      let row = this.cepingHzglDxpzbList[a];
     // console.log("this.cepingHzglDxpzbList:"+JSON.stringify(this.cepingHzglDxpzbList))
      let tableData = [];
      let hdids = [];
      let tableDataTwo=[];
      for (var i in this.cepingHzglHdfwbList) {
        // console.log("this.cepingHzglHdfwbList:"+JSON.stringify(this.cepingHzglHdfwbList))
       //  console.log("row:"+JSON.stringify(row))
        if (row["hd_" + this.cepingHzglHdfwbList[i].hdId]) {
          hdids.push(this.cepingHzglHdfwbList[i].hdId)
         
        }
        // else{
          
        //   if (a >= this.cepingHzglDxpzbList.length - 1) {
        //     this.getXQ(0);
        //   } else {
        //     this.viewMxAlls(a + 1);
        //   }
        // }
      }
      
      let j = 0;
      for (let xi in hdids) {
        let res = this.getHdhz(hdids[xi]);
        j++;
        let cepingHdglb = res.data.data.cepingHdglb;
        let cepingHdglCppmxbList = res.data.data.cepingHdglCppmxbList;
        let cepingHdglHdcphzbList = res.data.data.cepingHdglHdcphzbList;
        //this.cepingXmmxbList = res.data.data.cepingXmmxbList;
        let cepingHdglHdzhhzbList = res.data.data.cepingHdglHdzhhzbList;
        let cepingHdglHdhzmxbList = res.data.data.cepingHdglHdhzmxbList;
        
        //填表
        let dataObj = {};
        let data = cepingHdglHdzhhzbList;
        for (var i in data) {
          dataObj[(data[i].bcpDx == '部门' ? "dept" : "user") + "_" + (data[i].bcpDx == '部门' ? data[i].bcpDeptId : data[i].bcpUserId)] = data[i];
        }
        
        for (var i in cepingHdglHdcphzbList) {
          var info = cepingHdglHdcphzbList[i];
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpFz"] = info.cpFz;
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpDj"] = info.cpDj;
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpZf"] = info.cpZf;
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["hdQz"] = info.hdQz;
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["qzZf"] = info.qzZf;
        }
        
        for (var i in cepingHdglHdhzmxbList) {
          var info = cepingHdglHdhzmxbList[i];
          dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["zb_" + info.zbId] = info.zbFz;
        }
        let dataInfo = dataObj[(this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? "dept_" : "user_") + (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? row.deptId : row.userId)];
        dataInfo["hdName"] = cepingHdglb.hdName;

        let cppId = 0;
        for (var x in cepingHdglHdcphzbList) {
          let info = cepingHdglHdcphzbList[x];
          if (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子")) {
            if (info.bcpDeptId == row.deptId && info.bcpDx == "部门") {
              if (j == 1) {
                cppId = info.cppId;
              }
            }
          } else {
            if (info.bcpUserId == row.userId && info.bcpDx == "个人") {
              if (j == 1) {
                cppId = info.cppId;
              }
            }
          }
        }
       
        for (var x in cepingHdglCppmxbList) {
          let info = cepingHdglCppmxbList[x];
          if (info.cppId == cppId && j == 1) {
            let xmxxXmmx = info.xmxxXmmx;
            this.cepingHdglCppmxbInfo = info;
            this.xmxxXmmx = JSON.parse(xmxxXmmx);
            this.cepingXmmxbListTree = this.getTree(JSON.parse(xmxxXmmx), 0);
          }
        }
        
        tableData.push(dataInfo);
          // console.log("this.cepingXmmxbListTree:"+JSON.stringify(this.cepingXmmxbListTree))
          // console.log("tableData.tableData:"+JSON.stringify(tableData))
        if (j >= hdids.length) {
          let d = JSON.parse(JSON.stringify(tableData[0]));
          d.hdName = (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? row.deptName : row.userName);
          for (var i in tableData) {
            for (var k in tableData[i]) {
              if (k.indexOf("zb_") != -1) {
                if (d[k.replace("zb_", "js_")] == undefined) {
                  d[k.replace("zb_", "js_")] = tableData[i][k] * 1 * tableData[i].hdQz / 100;
                } else {
                  d[k.replace("zb_", "js_")] += tableData[i][k] * 1 * tableData[i].hdQz / 100;
                }
              }
            }
          }
          if (this.cepingHzglb.id < 69) {
            let hj = 0;
            for (var k in d) {
              if (k.indexOf("js_") != -1) {
                hj += d[k];
              }
            }
            let bl = row.df / hj;
            hj = 0;
            for (var k in d) {
              // if(k.indexOf("961") != -1)
              //   debugger
              if (k.indexOf("js_") != -1) {
                let db = d[k] * bl;
                let jg = Math.round(db * 100) / 100;
                d[k.replace("js_", "hj_")] = jg;
                d[k.replace("js_", "db_")] = db > jg ? -1 : (db < jg ? 1 : 0);
                hj += jg;

              }
            }
            hj = Math.round(hj * 100) / 100;
            if (hj != row.df) {
              let db = Math.round((hj - row.df) * 100) / 100;
              while (db != 0) {
                for (var k in d) {
                  if (k.indexOf("hj_") != -1) {
                    if (db > 0 && d[k.replace("hj_", "db_")] == 1) {
                      if (Math.round(d[k]) != d[k]) {
                        d[k] = Math.round((d[k] - 0.01) * 100) / 100;
                        db = Math.round((db - 0.01) * 100) / 100;
                      }
                    }
                    if (db < 0 && d[k.replace("hj_", "db_")] == -1) {
                      if (Math.round(d[k]) != d[k]) {
                        d[k] = Math.round((d[k] + 0.01) * 100) / 100;
                        db = Math.round((db + 0.01) * 100) / 100;
                      }
                    }
                    if (db == 0) {
                      break;
                    }
                  }
                }
              }
            }
          }
          d.cpFz = row.df;
       
          this.tableData.push(d);
          
        }
      }
      
      if (a >= this.cepingHzglDxpzbList.length - 1) {
        // debugger
        this.getXQ(0);
      } else {
        this.viewMxAlls(a + 1);
      }
      
      if(hdids.length == 0){
        if (a >= this.cepingHzglDxpzbList.length - 1) {
          this.getXQ(0);
        } else {
          this.viewMxAlls(a + 1);
        }
      }
    },
    async getXQ(a) {

     // this.loading.text = '正在汇总计算详情，请销后...';
      var hdids = [];
      for (var i in this.cepingHzglHdfwbList) {
        if (hdids.indexOf(this.cepingHzglHdfwbList[i].hdId) == -1) {
          hdids.push(this.cepingHzglHdfwbList[i].hdId);
        }
      }
      var data1 = [];
      var data2 = [];
      //console.log("YOUME:"+JSON.stringify(this.tableData))
      for (var i in this.tableData) {
        if (this.tableData[i].bcpDx == "个人") {
          data2.push(this.tableData[i].bcpUserId)
        } else {
          data1.push(this.tableData[i].bcpDeptId)
        }
      }
      await getBcpDfLists(hdids.join(), data1.length == 0 ? "0" : data1.join(), data2.length == 0 ? "0" : data2.join()).then(res => {
        this.dfInfos = res.data.data;
        this.getXQs(a, hdids);
      })
    },
    getCeping(table,a,hdidsTwo){
      this.loading.text = '正在汇总计算详情，请销后...';
      var hdids = [];
      for (var i in this.cepingHzglHdfwbList) {
        if (hdids.indexOf(this.cepingHzglHdfwbList[i].hdId) == -1) {
          hdids.push(this.cepingHzglHdfwbList[i].hdId);
        }
      }
      var data1 = [];
      var data2 = [];
      for (var i in table) {
        if (this.tableData[i].bcpDx == "个人") {
          data2.push(this.tableData[i].bcpUserId)
        } else {
          data1.push(this.tableData[i].bcpDeptId)
        }
      }
      //console.log("this.tableData:"+JSON.stringify(this.tableData))
      getBcpDfLists(hdids.join(), data1.length == 0 ? "0" : data1.join(), data2.length == 0 ? "0" : data2.join()).then(res => {
        this.dfInfos = res.data.data;
        // this.tableData=table
        // this.loading.close()
        
      })
           
    },
    getBcpDf(t, id) {
      let res = {
        data: {
          data: this.dfInfos[t][id]
        }
      }
      return res;
    },
    // selectDf() {
    //   for(var a in this.tableData){
    //     let res = this.getBcpDf(this.tableData[a].bcpDx == "个人" ? "user" : "dept", this.tableData[a].bcpDx == "个人" ? this.tableData[a].bcpUserId : this.tableData[a].bcpDeptId);
    //     let cepingHdglXpxxDfjlBfbList = res.data.data.cepingHdglXpxxDfjlBfbList;
    //     let cepingHdglXpxxbList = res.data.data.cepingHdglXpxxbList;
    //     let cepingHdglXpxxbs = {};
    //     for (var i in cepingHdglXpxxbList) {
    //       cepingHdglXpxxbs[cepingHdglXpxxbList[i].id] = cepingHdglXpxxbList[i];
    //     }
    //     for (var i in cepingHdglXpxxDfjlBfbList) {
    //       let info = cepingHdglXpxxDfjlBfbList[i];
    //       let xpCode = cepingHdglXpxxbs[info.xpId].xpCode;
    //       let xp = ""
    //       if (xpCode.length > 11) {
    //         xp = xpCode.substr(0, 2);
    //       } else {
    //         xp = xpCode.substr(0, 1);
    //       }
    //       this.tableData[a][xp + '_' + info.zbId + '_df'] = 0;
    //       if (info.fzFz < this.xyfz) {
    //         this.tableData[a][xp + '_' + info.zbId + '_df']++;
    //       }
    //     }
    //   }
    // },
    getXQs(a, hdids) {

      this.loading.text = '正在汇总计算详情（' + (a + 1) + '/' + (this.tableData.length) + '），请销后...';
      let res = this.getBcpDf(this.tableData[a].bcpDx == "个人" ? "user" : "dept", this.tableData[a].bcpDx == "个人" ? this.tableData[a].bcpUserId : this.tableData[a].bcpDeptId);
      let cepingHdglXpxxDfjlBfbList = res.data.data.cepingHdglXpxxDfjlBfbList;
      let cepingHdglXpxxbList = res.data.data.cepingHdglXpxxbList;
      let cepingHdglXpxxbs = {};
      for (var i in cepingHdglXpxxbList) {
        cepingHdglXpxxbs[cepingHdglXpxxbList[i].id] = cepingHdglXpxxbList[i];
      }
      for (var i in cepingHdglXpxxDfjlBfbList) {
        let info = cepingHdglXpxxDfjlBfbList[i];

        if(cepingHdglXpxxbs[info.xpId]){
          }else{
            continue;
        }
        let xpCode = cepingHdglXpxxbs[info.xpId].xpCode;
        let xp = ""
        if (xpCode.length > 11) {
          xp = xpCode.substr(0, 2);
        } else {
          xp = xpCode.substr(0, 1);
        }
        if (!this.tableData[a][info.zbId + '_info']) {
          this.tableData[a][info.zbId + '_info'] = {};
        }
        if (!this.tableData[a][xp + '_' + info.zbId + '_xp']) {
          this.tableData[a][xp + '_' + info.zbId + '_xp'] = 0;
          this.tableData[a][xp + '_' + info.zbId + '_df'] = 0;
          this.tableData[a][xp + '_' + info.zbId + '_zf'] = 0;
          this.tableData[a][xp + '_' + info.zbId + '_pj'] = 0;
          this.tableData[a][xp + '_' + info.zbId + '_sl'] = 0;
        }
        this.tableData[a][xp + '_' + info.zbId + '_zf'] += info.fzFz;
        this.tableData[a][xp + '_' + info.zbId + '_xp']++;
        if (info.fzFz < this.xyfz) {
          this.tableData[a][xp + '_' + info.zbId + '_df']++;
        }
        this.tableData[a][xp + '_' + info.zbId + '_qz'] = info.zbQz;
        this.tableData[a][xp + '_' + info.zbId + '_pj'] = Math.round(this.tableData[a][xp + '_' + info.zbId + '_zf'] / this.tableData[a][xp + '_' + info.zbId + '_xp'] * 100 * info.zbQz / 100) / 100;
        this.tableData[a][info.zbId + '_info'][xp] = this.tableData[a][xp + '_' + info.zbId + '_pj'] * 1;

      }

      //原值69，不知道什么意义
      // if (this.cepingHzglb.id < 69) {
      if (this.cepingHzglb.id < 1000) {

      } else {
        //console.log(this.tableData[a])
        // console.log(this.cepingHzglDxpzbList[a])
        let hj = 0;
        for (var i in this.tableData[a]) {
          var row = this.tableData[a];
          if (i.indexOf("_info") != -1) {
            var info = row[i];
            var zbId = i.replace("_info", "");

            var gs = "";
            if (this.cepingHzglb.hzFs == "公式") {
              gs = this.cepingHzglb.hzJsgs;
            }
            var x = 0,cppQz,cpQz,qz;
            for (var j in info) {
              if(this.cepingHzglDxpzbList[a][j + "_cppQz"]&&this.cepingHzglDxpzbList[a][j + "_cpQz"]){
                  cppQz = this.cepingHzglDxpzbList[a][j + "_cppQz"] * 1;
                   cpQz = this.cepingHzglDxpzbList[a][j + "_cpQz"] * 1;
                   qz = cppQz * cpQz / 100 / 100;
                    if (this.cepingHzglb.hzFs == "合计") {
                    gs += (gs == "" ? "" : "+") + (info[j] * qz);
                  } else if (this.cepingHzglb.hzFs == "平均") {
                    gs += (gs == "" ? "" : "+") + (info[j] * qz);
                  } else {
                    gs = gs.replace(j, info[j] * qz);
                  }
              }
              x++;
            }
            if (this.cepingHzglb.hzFs == "平均") {
              gs = "(" + gs + ")/" + x;
            }
            console.log()
            //票中无值的替换成指定值 1
            gs = gs.replace(/[A-Z][0-9]?/g,'1')
            var db = eval(gs);
            // var jg = Math.round(db * 100) / 100;
            var jg = this.keepTwoDecimalFull(db,4);
            this.tableData[a]['hjy_' + zbId] = jg;
            this.tableData[a]['hj_' + zbId] = jg;
            this.tableData[a]['db_' + zbId] = db > jg ? -1 : (db < jg ? 1 : 0);
            hj += jg;
          }
        }

        // console.log(this.tableData[a])
        // hj = Math.round(hj * 100) / 100;
       // console.log("hqqian"+hj)
        hj = this.keepTwoDecimalFull(hj,4);
        //console.log("hq后"+hj)
        var row1 = this.tableData[a];
        var d = this.tableData[a];
        if (hj != row1.cpFz) {
          let db = Math.round((hj - row1.cpFz) * 100) / 100;
          let q = 0;
          while (db != 0) {
            for (var k in d) {
              q++;
              if (k.indexOf("hj_") != -1) {
                if (db > 0 && d[k.replace("hj_", "db_")] == 1) {
                  if (Math.round(d[k]) != d[k]) {
                    d[k] = Math.round((d[k] - 0.01) * 100) / 100;
                    db = Math.round((db - 0.01) * 100) / 100;
                  }
                }
                if (db < 0 && d[k.replace("hj_", "db_")] == -1) {
                  if (Math.round(d[k]) != d[k]) {
                    d[k] = Math.round((d[k] + 0.01) * 100) / 100;
                    db = Math.round((db + 0.01) * 100) / 100;
                  }
                }
                if (db == 0) {
                  break;
                }
              }
            }
            if (q > 1000) {
              break;
            }
          }
        }
      }


      if (a >= this.tableData.length - 1) {
        this.loading.close();
        this.xqDialogVisible = true;
        let t = this.mxLx + "";
        this.mxLx = "";
        this.$nextTick(() => {
          this.mxLx = t;
        })
        //console.log(this.tableData)
      } else {
        this.getXQs(a + 1, hdids);
      }

    },
    keepTwoDecimalFull(num, p) {
      let result = parseFloat(num);
      if (isNaN(result)) {
        console.log('传递参数错误，请检查！');
        return num;
      }
      let multiplicator = Math.pow(10, p);
      result = Math.round(num * multiplicator) / multiplicator;
      let s_x = result.toString();
      let pos_decimal = s_x.indexOf('.');
      if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
      }
      while (s_x.length <= pos_decimal + p) {
        s_x += '0';
      }
      return s_x;
    },
    getDfsm(row) {
      let text = "";
      var map = {};
      for (var x in this.xmxxXmmx) {
        map[this.xmxxXmmx[x].id] = 1;
      }
      for (var i in this.tableData) {
        let ys = false;
        if (row.userLx == "个人") {
          if (this.tableData[i].bcpUserId == row.userId) {
            ys = true;
          }
        } else {
          if (this.tableData[i].bcpDeptId == row.deptId) {
            ys = true;
          }
        }
        if (ys) {
          var info = this.tableData[i];
          //console.log(info);
          var jg = {}
          for (let j in info) {
            if (j.indexOf("_df") != -1) {
              if (info[j] > 0) {
                let xp = j.split("_")[0];
                let zb = j.split("_")[1];
                if(map[zb]){
                  let df = info[j];
                  if (!jg[zb]) {
                    jg[zb] = {}
                  }
                  jg[zb][xp] = df;
                }
              }
            }
          }
          var y = 1;
          for (var j in jg) {
            let name = "";
            for (var x in this.xmxxXmmx) {
              if (this.xmxxXmmx[x].id == j * 1) {
                name = this.xmxxXmmx[x].zbMc;
              }
            }
            text += y + "、" + name + "：";
            y++;
            for (var s in jg[j]) {
              text += s + " " + jg[j][s] + "票；";
            }
            text += "<br>";
          }
        }
      }
      return text;
    },
    // viewMx(row) {
    //   this.loading = this.$loading({
    //     lock: true,
    //     text: '正在汇总计算，请销后...',
    //     spinner: 'el-icon-loading',
    //     background: 'rgba(0, 0, 0, 0.7)'
    //   });
    //   let tableData = [];
    //   let hdids = [];
    //   for (var i in this.cepingHzglHdfwbList) {
    //     if (row["hd_" + this.cepingHzglHdfwbList[i].hdId]) {
    //       hdids.push(this.cepingHzglHdfwbList[i].hdId)
    //     }
    //   }
    //   let j = 0;
    //   for (let i in hdids) {
    //     setTimeout(() => {
    //       hdhz(hdids[i]).then(res => {
    //         j++;
    //         let cepingHdglb = res.data.data.cepingHdglb;
    //         let cepingHdglCppmxbList = res.data.data.cepingHdglCppmxbList;
    //         let cepingHdglHdcphzbList = res.data.data.cepingHdglHdcphzbList;
    //         //this.cepingXmmxbList = res.data.data.cepingXmmxbList;
    //         let cepingHdglHdzhhzbList = res.data.data.cepingHdglHdzhhzbList;
    //         let cepingHdglHdhzmxbList = res.data.data.cepingHdglHdhzmxbList;
    //         //填表
    //         let dataObj = {};
    //         let data = cepingHdglHdzhhzbList;
    //         for (var i in data) {
    //           dataObj[(data[i].bcpDx == '部门' ? "dept" : "user") + "_" + (data[i].bcpDx == '部门' ? data[i].bcpDeptId : data[i].bcpUserId)] = data[i];
    //         }

    //         for (var i in cepingHdglHdcphzbList) {
    //           var info = cepingHdglHdcphzbList[i];
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpFz"] = info.cpFz;
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpDj"] = info.cpDj;
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["cpZf"] = info.cpZf;
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["hdQz"] = info.hdQz;
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["qzZf"] = info.qzZf;
    //         }

    //         for (var i in cepingHdglHdhzmxbList) {
    //           var info = cepingHdglHdhzmxbList[i];
    //           dataObj[(info.bcpDx == '部门' ? "dept" : "user") + "_" + (info.bcpDx == '部门' ? info.bcpDeptId : info.bcpUserId)]["zb_" + info.zbId] = info.zbFz;
    //         }
    //         let dataInfo = dataObj[(this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? "dept_" : "user_") + (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? row.deptId : row.userId)];
    //         dataInfo["hdName"] = cepingHdglb.hdName;

    //         let cppId = 0;
    //         for (var x in cepingHdglHdcphzbList) {
    //           let info = cepingHdglHdcphzbList[x];
    //           if (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子")) {
    //             if (info.bcpDeptId == row.deptId && info.bcpDx == "部门") {
    //               if (j == 1) {
    //                 cppId = info.cppId;
    //               }
    //             }
    //           } else {
    //             if (info.bcpUserId == row.userId && info.bcpDx == "个人") {
    //               if (j == 1) {
    //                 cppId = info.cppId;
    //               }
    //             }
    //           }
    //         }
    //         for (var x in cepingHdglCppmxbList) {
    //           let info = cepingHdglCppmxbList[x];
    //           if (info.cppId == cppId && j == 1) {
    //             let xmxxXmmx = info.xmxxXmmx;
    //             this.cepingHdglCppmxbInfo = info;
    //             this.cepingXmmxbListTree = this.getTree(JSON.parse(xmxxXmmx), 0);
    //           }
    //         }
    //         // debugger
    //         tableData.push(dataInfo);
        
    //         if (j >= hdids.length) {
    //           let d = JSON.parse(JSON.stringify(tableData[0]));
    //           d.hdName = (this.cepingHzglb.hzDx == "部门" || (this.cepingHzglb.hzDx == "个人" && row.bcpDx == "班子") ? row.deptName : row.userName);

    //           for (var i in tableData) {
    //             for (var k in tableData[i]) {
    //               if (k.indexOf("zb_") != -1) {
    //                 if (d[k.replace("zb_", "js_")] == undefined) {
    //                   d[k.replace("zb_", "js_")] = tableData[i][k] * 1 * tableData[i].hdQz / 100;
    //                 } else {
    //                   d[k.replace("zb_", "js_")] += tableData[i][k] * 1 * tableData[i].hdQz / 100;
    //                 }
    //               }
    //             }
    //           }

    //           let hj = 0;
    //           for (var k in d) {
    //             if (k.indexOf("js_") != -1) {
    //               hj += d[k];
    //             }
    //           }
    //           //console.log(d)
    //           let bl = row.df / hj;
    //           hj = 0;
    //           for (var k in d) {
    //             if (k.indexOf("js_") != -1) {
    //               let db = d[k] * bl;
    //               let jg = Math.round(db * 100) / 100;
    //               d[k.replace("js_", "hj_")] = jg;
    //               d[k.replace("js_", "db_")] = db > jg ? -1 : (db < jg ? 1 : 0);
    //               hj += jg;
    //             }
    //           }
    //           hj = Math.round(hj * 100) / 100;
    //           //console.log(d)
    //           if (hj != row.df) {
    //             let db = Math.round((hj - row.df) * 100) / 100;
    //             while (db != 0) {
    //               for (var k in d) {
    //                 if (k.indexOf("hj_") != -1) {
    //                   if (db > 0 && d[k.replace("hj_", "db_")] == 1) {
    //                     if (Math.round(d[k]) != d[k]) {
    //                       d[k] = Math.round((d[k] - 0.01) * 100) / 100;
    //                       db = Math.round((db - 0.01) * 100) / 100;
    //                       if (db <= 0) {
    //                         break;
    //                       }
    //                     }
    //                   }
    //                   if (db < 0 && d[k.replace("hj_", "db_")] == -1) {
    //                     if (Math.round(d[k]) != d[k]) {
    //                       d[k] = Math.round((d[k] + 0.01) * 100) / 100;
    //                       db = Math.round((db + 0.01) * 100) / 100;
    //                       if (db >= 0) {
    //                         break;
    //                       }
    //                     }
    //                   }

    //                 }
    //               }
    //             }
    //           }
    //            d.cpFz = row.df;
    //           //console.log("d.cpFz----------------------------------------,",d.cpFz)
    //           this.tableData = [];
    //           this.tableData.push(d);
    //           this.getXQ(0, hdids);
    //         }
    //       })
    //     }, i * 100)
    //   }
    // },
    getDjmx() {
      let r = false;
      for (var i in this.mxList) {
        if (this.mxList[i].cpqz != 100) {
          return true;
        }
      }
      return r;
    },
    getCppQz() {
      let r = false;
      for (var i in this.mxList) {
        if (this.mxList[i].cppQz != 100) {
          return true;
        }
      }
      return r;
    },
    getTree(ary, pid) {
      return ary.filter(v => {
        if (v.pid === pid) {
          if (v.pid === 0) {
            v.xh = 1;
          } else {
            for (var a = 0; a < ary.length; a++) {
              if (ary[a].id == v.pid) {
                v.xh = ary[a].xh + 1;
              }
            }
          }
          return v
        }
      }).map(v => {
        const children = this.getTree(ary, v.id);
        if (children.length) v.children = this.getTree(ary, v.id);
        return v
      });
    },
    exportExcelAB() {
      const excelName = this.cepingHzglb.hzName + "_明细"
      try {
        const $e = this.$refs['zbABTable'].$el
        let $table = $e.querySelector('.el-table__fixed')
        if (!$table) {
          $table = $e
        }
        const wb = XLSX.utils.table_to_book($table, {
          raw: true
        })

        const wbout = XLSX.write(wb, {
          bookType: 'xlsx',
          bookSST: true,
          type: 'array'
        })
        FileSaver.saveAs(
          new Blob([wbout], {
            type: 'application/octet-stream'
          }),
          `${excelName}.xlsx`,
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.error(e)
      }
    },
    exportExcelXq() {
      const excelName = this.cepingHzglb.hzName + "_详情"
      try {
        const $e = this.$refs['xqABTable'].$el
        let $table = $e.querySelector('.el-table__fixed')
        if (!$table) {
          $table = $e
        }
        const wb = XLSX.utils.table_to_book($table, {
          raw: true
        })

        const wbout = XLSX.write(wb, {
          bookType: 'xlsx',
          bookSST: true,
          type: 'array'
        })
        FileSaver.saveAs(
          new Blob([wbout], {
            type: 'application/octet-stream'
          }),
          `${excelName}.xlsx`,
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.error(e)
      }
    }
  }
}
</script>

<style scoped>
</style>
